package algorithm;

public class leetcode_0704 {
    public int search(int[] nums, int target) {
        int len=nums.length;
        return binary(nums,0,len-1,target);
    }
    public int binary(int[] num,int left,int right,int target){
        if(right-left<=1){
            if(num[left]==target) return left;
            else if(num[right]==target) return right;
            else return -1;
        }
        int mid=(left+right)/2;
        if(target<=num[mid]){
            return binary(num,left,mid,target);
        }
        else{
            return binary(num,mid+1,right,target);
        }
    }
}
